﻿using System;
using System.Collections.Generic;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TracNghiemV1.Database;

namespace TracNghiemV1.DAO
{
    class QuestionTopicMapDao
    {
        private static TestDataDataContext m_dataContext = null;

        public static void AddQuestionTopicMap(QUESTION_TOPIC_MAP newQuestionTopicMap)
        {

            m_dataContext = DataContextDao.GetInstance();

            m_dataContext.QUESTION_TOPIC_MAPs.InsertOnSubmit(newQuestionTopicMap);
            m_dataContext.SubmitChanges();
        }

        public static void DeleteQuestionTopicMap(int questionId)
        {
            m_dataContext = DataContextDao.GetInstance();

            IList<QUESTION_TOPIC_MAP> lstQS = FindQuestionTopicMapListWithQuestionId(questionId);

            foreach (QUESTION_TOPIC_MAP qt in lstQS)
            {
                m_dataContext.QUESTION_TOPIC_MAPs.DeleteOnSubmit(qt);
            }


            m_dataContext.SubmitChanges();
        }

        public static IList<QUESTION_TOPIC_MAP> FindQuestionTopicMapListWithQuestionId(int questionId)
        {
            m_dataContext = DataContextDao.GetInstance();

            var questionTopicMaps = from p in m_dataContext.QUESTION_TOPIC_MAPs
                                where p.QUESTION_ID == questionId
                                select p;
            return questionTopicMaps.ToList();
        }
    }
}
